home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 8: LINUX Games
/
Linux Cubed Series 8 - LINUX Games.iso
/
games
/
video
/
pictetri.src
/
pictetri
/
pictetris-src
/
utils.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-12-19
|
4KB
|
112 lines
/***************************************************************************\
|* *|
|* utils.c: A version of Tetris to run on Linux SVGAlib console. *|
|* This module supplies all the function that I will need, *|
|* but which are not intrinsically a part of Tetris itself. *|
|* *|
|* Authors: Mike Taylor (mirk@uk.ac.warwick.cs) & *|
|* Arturo Espinosa (arturo@nuclecu.unam.mx) *|
|* Started: Fri May 26 12:26:05 BST 1989 (tetris for terminals) *|
|* Dic 1, 1995 (pictetris) *|
|* *|
\***************************************************************************/
#include <varargs.h>
#include <stdio.h>
#include <stdlib.h>
#include <jlib.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/time.h>
#include <errno.h>
/* Stuff needed to run under Linux */
char* l_rindex (const char* s, int c)
{return strrchr (s, c);}
#include "pictetris.h"
#include "utils.h"
#include "screen.h"
/*-------------------------------------------------------------------------*/
extern char *rindex ();
extern char *getenv ();
/***************************************************************************\
|* *|
|* The function basename() acts like the UNIX(tm) command of the same *|
|* name. It takes as its argument a string, and returns the last path- *|
|* component of that string, (ie, the section after the last '/'), or *|
|* the whole string if it has no '/'. *|
|* *|
\***************************************************************************/
char *basename (name)
char *name;
{
char *slash;
if (slash = l_rindex (name, '/'))
return (slash+1);
else
return (name);
}
/***************************************************************************\
|* *|
|* This is my home-made varargs-based version of C++'s neat function of *|
|* the same name. It saves all that tedious mucking about with static *|
|* buffers which you sprintf into, then forget all about, by basically *|
|* being a sprintf with its own statis storage. It takes as arguments *|
|* exactly the same things as printf(3), and returns a pointer to the *|
|* resultant string. *|
|* *|
\***************************************************************************/
/*VARARGS*/
char *form (va_alist)
va_dcl
{
va_list pvar;
char *fmt_string;
static char result[LINELEN];
va_start (pvar);
fmt_string = va_arg (pvar, char*);
(void) vsprintf (result, fmt_string, pvar);
va_end (pvar);
return (result);
}
/***************************************************************************\
|* *|
|* This is yer bog-standard "print a message and quit" function, except *|
|* that it checks to see if we are in curses(3x), and if so, takes us *|
|* out before doing its stuff. The arguments are an integer, the exit *|
|* status, and a string containing an error report, to which will be *|
|* prepended the program name when it is printed. If the status code *|
|* is LE_OK, (ie. nothing went wrong), no message is printed. *|
|* *|
\***************************************************************************/
void die (status, line)
int status;
char *line;
{
if (in_curses) {
myrefresh ();
kb_closedown();
screen_restore_video_mode();
}
if (status != LE_OK)
(void) printf ("%s: %s\n", prog_name, line);
#ifndef LOCKF
(void) unlink (LOCK_FILE); /* Just in case :-) */
#endif /* LOCKF */
exit (status);
}
/*-------------------------------------------------------------------------*/